#include <opencv2/opencv.hpp>
#include <cstdlib>
#include <iostream>

using namespace std;



int threshold(const char *fileName)
{
	if(fileName == NULL) { cout << "param invalid " << endl; return -1; }

	cv::Mat Igray = cv::imread(fileName, cv::IMREAD_GRAYSCALE);

	if (Igray.empty()) { cout << "Can not load " << fileName << endl; return -1; }

	cv::Mat It, Iat;

	// Thresholds.
	//
	cv::threshold(
		Igray,
		It,
		15,
		255,
		cv::THRESH_BINARY|cv::THRESH_OTSU);

	cv::adaptiveThreshold(
		Igray,
		Iat,
		255,
		//cv::ADAPTIVE_THRESH_GAUSSIAN_C,
		cv::ADAPTIVE_THRESH_MEAN_C,
		cv::THRESH_BINARY,
		101,
		1
	);

	cv::imshow("Raw", Igray);
	cv::imshow("Threshold", It);
	cv::imshow("Adaptive Threshold", Iat);

	return 0;
}